package ma.cdm.compteRenduVO;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;

public class PersonneVO implements Serializable, Externalizable {
    private String idExterne;
	private String matricule;
	private String prenom;
	private String nom;
	private boolean present;
	private String fonction;
	private String civilite;
	private String departement;
	private String mail;
	private byte[] image;
	private String company;
	private String telephone;
	private boolean admin;
	private RoleVO role;
	private String imageUrl ;
	

	public PersonneVO(String matricule) {
		super();
		this.matricule = matricule;
	}


	public PersonneVO(String matricule, String prenom, String nom,
			boolean present) {
		super();
		this.matricule = matricule;
		this.prenom = prenom;
		this.nom = nom;
		this.present = present;
	}

	
	public PersonneVO(String idExterne, String prenom, String nom,
			String fonction, String civilite, String mail, String company,
			String telephone) {
		super();
		this.idExterne = idExterne;
		this.prenom = prenom;
		this.nom = nom;
		this.fonction = fonction;
		this.civilite = civilite;
		this.mail = mail;
		this.company = company;
		this.telephone = telephone;
	}


	public PersonneVO(String matricule, String prenom, String nom,
			boolean present, String fonction, String civilite,
			String departement, String mail, byte[] image, String company,String telephone) {
		super();
		this.matricule = matricule;
		this.prenom = prenom;
		this.nom = nom;
		this.present = present;
		this.fonction = fonction;
		this.civilite = civilite;
		this.departement = departement;
		this.mail = mail;
		this.image = image;
		this.company = company;
		this.telephone = telephone;
	}


	public PersonneVO(String matricule, String prenom, String nom,
			String civilite, String departement) {
		super();
		this.matricule = matricule;
		this.prenom = prenom;
		this.nom = nom;
		this.civilite = civilite;
		this.departement = departement;
	}


	public PersonneVO() {
		super();
	}


	public String getIdExterne() {
		return idExterne;
	}


	public void setIdExterne(String idExterne) {
		this.idExterne = idExterne;
	}


	public String getImageUrl() {
		return imageUrl;
	}


	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}


	public RoleVO getRole() {
		return role;
	}


	public void setRole(RoleVO role) {
		this.role = role;
	}


	public boolean isAdmin() {
		return admin;
	}


	public void setAdmin(boolean admin) {
		this.admin = admin;
	}


	public String getTelephone() {
		return telephone;
	}


	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}


	public String getFonction() {
		return fonction;
	}


	public void setFonction(String fonction) {
		this.fonction = fonction;
	}


	public String getCivilite() {
		return civilite;
	}


	public void setCivilite(String civilite) {
		this.civilite = civilite;
	}


	public String getDepartement() {
		if(departement == null && matricule == null)
		{
			return company;
		}
		return departement;
	}


	public void setDepartement(String departement) {
		this.departement = departement;
	}


	public String getMail() {
		return mail;
	}


	public void setMail(String mail) {
		this.mail = mail;
	}


	public byte[] getImage() {
		return image;
	}


	public void setImage(byte[] image) {
		this.image = image;
	}


	public String getCompany() {
		return company;
	}


	public void setCompany(String company) {
		this.company = company;
	}


	public String getMatricule() {
		return matricule;
	}

	public void setMatricule(String matricule) {
		this.matricule = matricule;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public boolean isPresent() {
		return present;
	}

	public void setPresent(boolean present) {
		this.present = present;
	}

	public void writeExternal(ObjectOutput output) throws IOException {
		output.writeObject(admin);
         output.writeObject(civilite);
         output.writeObject(company);
         output.writeObject(departement);
         output.writeObject(fonction);
         output.writeObject(idExterne);
         output.writeObject(image);
         output.writeObject(imageUrl);
         output.writeObject(mail);
         output.writeObject(matricule);
         output.writeObject(nom);
         output.writeObject(prenom);
         output.writeObject(present);
         output.writeObject(role);
         output.writeObject(telephone);
	}

	public void readExternal(ObjectInput input) throws IOException,
			ClassNotFoundException {
		 admin =(Boolean) input.readObject(); 
         civilite =(String) input.readObject();
         company = (String)input.readObject();
         departement =(String) input.readObject();
         fonction =(String) input.readObject();
         idExterne =(String) input.readObject();
         image =(byte[]) input.readObject() ;
         imageUrl =(String) input.readObject() ;
         mail =(String) input.readObject() ;
         matricule =(String) input.readObject() ;
         nom = (String)input.readObject() ;
         prenom =(String) input.readObject();
         present =(Boolean) input.readObject();
         role =(RoleVO) input.readObject();
         telephone =(String) input.readObject();
	} 

	@Override
	public String toString() {	
		String title = civilite+" "+nom+ " "+prenom;
		if(matricule == null)
		{
			title+= " ("+company+")";
		}
			return title;
		
		//return prenom+" "+nom +"("+((matricule != null)?matricule:"externe")+"); ";
	}
}
